package com.web.accountingEntry.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.web.transaction.entity.Transaction;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.math.BigDecimal;
import java.time.LocalDate;

@ToString
@ApiModel
@Getter
@Setter
public class AccountingJournal extends AccountingEntry {


	private String buyOrSell;

	public static AccountingJournal setAccountingEntry(AccountingJournal ae, Transaction tr){

		if (ae == null){
			return new AccountingJournal();
		}
		ae.setAcDate(tr.getTradeDate());
		ae.setDealNo(tr.getDealNo());
		ae.setCurrency(Transaction.TX_BUY.equals(ae.getBuyOrSell()) ? tr.getWithdrawalCcy():tr.getDepositeCcy());
		if(Transaction.TX_BUY.equals(ae.getBuyOrSell())) {
			ae.setCreditAmt(tr.getWithdrawalAmt());
			ae.setDebitAmt(BigDecimal.ZERO);
		}else{
			ae.setCreditAmt(BigDecimal.ZERO);
			ae.setDebitAmt(tr.getDepositedAmt());
		}
		return ae;
	}
}
